#include "util_delay.h"

// 好的延时函数必须抵御中断和更新系统时间
void sig_handler(int s)
{
    printf("ctrl+c press down,call settimeofday\n");
    struct timeval tv;
    tv.tv_sec = 1717632000;
    settimeofday(&tv, NULL);
}

void sig_alarm_handler(int s)
{
    printf("timer timeout,call %s\n", __FUNCTION__);
}

int main(void)
{
    int ret;
    signal(SIGINT, sig_handler);
    signal(SIGALRM, sig_alarm_handler);
    int t1, t2;
    printf("按回车进行delays_with_sleep测试\n");
    getchar();
    alarm(2);
    t1 = get_sys_uptime();
    delays_with_sleep(5);
    t2 = get_sys_uptime();
    printf("elaspsed ms = %d\n", t2 - t1);

    printf("按回车进行delays_with_select测试\n");
    getchar();
    alarm(2);
    t1 = get_sys_uptime();
    delays_with_select(5);
    t2 = get_sys_uptime();
    printf("elaspsed ms = %d\n", t2 - t1);

    printf("按回车进行sleep测试\n");
    getchar();
    alarm(2);
    t1 = get_sys_uptime();
    sleep(5);
    t2 = get_sys_uptime();
    printf("elaspsed ms = %d\n", t2 - t1);
    return 0;
}